package com.leetcode;

import com.leetcode.common.TreeNode;

/**
 * 404. 左叶子之和
 *
 * @author fy
 * @date 2022/4/20 21:38
 */
public class Solution404 {

    public int sumOfLeftLeaves(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int sum = 0;
        // 如何定义一个节点是左节点
        if (root.left != null && root.left.left == null && root.left.right == null) {
            sum += root.left.val;
        }
        return sum + sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
    }

}
